package com.hspedu.newData.dmsxl.数组.模拟;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-09 
 * @Version: 1.0
 */

// 根据数学的推导
    // 先转置，后根据中心轴对称翻转
public class LC48旋转图像 {

    public void rotate(int[][] matrix) {

        int size = matrix.length;

        // 转置
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < i; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }

        // 轴翻转
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size/2; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[i][size-j-1];
                matrix[i][size-j-1] = temp;
            }
        }
    }


    @Test
    public void test() {
        // 测试代码

        rotate(new int[][]{{1,2,3},{4,5,6},{7,8,9}});
    }


}
